// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

#include "Clock.h"

Clock::Clock(double _startjd)
{
	timer = new Ogre::Timer();
	timeaccel = 1;
	startjd = _startjd;
	jd = startjd;
	dt = 0;
	simt = 0;
	lastt = timer->getMicroseconds();
}

Clock::~Clock(void)
{
	delete timer;
}

void Clock::tick()
{
	newt = timer->getMicroseconds();
	dt = ((newt - lastt) / 1000000.) * timeaccel;
	lastt = newt;
	jd += dt/(3600.0 * 24.0);
}

void Clock::incTimeAccel()
{
	timeaccel *= 10;
}

void Clock::decTimeAccel()
{
	timeaccel /= 10;
}

void Clock::reset(double newjd)
{
	timer->reset();
	if (newjd != 0.0)
		jd = newjd;
	else
		jd = startjd;
	timeaccel = 1;
	dt = 0;
	simt = 0;
	lastt = timer->getMicroseconds();
}



